package repo

import (
	"mine-info-server/domain/common-context/model/blessing-word-aggregate/aggregate"
	"mine-info-server/infra/database/mysql/common-context/blessing-word/convertor"
	"mine-info-server/infra/database/mysql/common-context/blessing-word/dao"
)

/*
   @author:zhongyang
   @date:2023/4/12
   @description:鸡汤文案-仓储层实现
*/

type BlessingWordRepo struct {
	convertor convertor.BlessingWordConvertor
}

func NewBlessingWordRepo() *BlessingWordRepo {
	return &BlessingWordRepo{}
}

func (b *BlessingWordRepo) GetMaxId() (int, error) {
	wordDao := dao.NewBlessingWordDao()
	return wordDao.GetMaxId()
}

func (b *BlessingWordRepo) GetBlessingWordById(wordId string) (*aggregate.BlessingWordAggregate, error) {
	wordDao := dao.NewBlessingWordDao()
	wordPO, err := wordDao.GetBlessingWordById(wordId)
	if err != nil {
		return nil, err
	}
	return b.convertor.CreateAggregateByOption(convertor.WithBlessingWordPO(wordPO)), nil
}
